package com.fxm.controller;

import com.fxm.client.RecordClient;
import com.fxm.returns.RespTable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/record")
@Slf4j
@Api(value = "答题记录", tags = "答题记录")
public class RecordController {

    @Resource
    private RecordClient recordClient;

    @GetMapping("/list")
    @ApiOperation(value = "答题记录总览列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true)
    })
    public RespTable recordList(@RequestParam(value = "page", required = true) Integer page,
                              @RequestParam(value = "limit", required = true) Integer limit) {
        RespTable respTable = recordClient.recordList(page, limit);
        return respTable;
    }

    @GetMapping("/search")
    @ApiOperation(value = "搜索用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "username", value = "用户昵称", required = false)
    })
    public RespTable ruleSearch(@RequestParam(value = "page", required = true) Integer page,
                                @RequestParam(value = "limit", required = true) Integer limit,
                                @RequestParam(value = "username", required = false) String username) {
        RespTable respTable = recordClient.searchRecord(page, limit, username);
        return respTable;
    }

}
